package heima_design.model06;
/**
 * @ClassName: Singleton
 * @Description:  解决双重检查锁模式带来空指针异常的问题,使用了volatile关键字后，重排序被禁止，所有的写（write）操作都将发生在读（read）操作之前。
 * @Version: v1.0.0
 * @Author: tamir
 * @Date: 2022/06/02
 * Modification History:
 * Date             Author      Version     Description
 * -------------------------------------------------------------
 * 2022/06/02      tamir        v1.0.0      创建
 */
public class Singleton {
	private Singleton (){}
	
	private  static volatile Singleton instance;
	
	public static Singleton getInstance(){
		if (instance == null){
			synchronized (Singleton.class){
				if (instance == null){
					instance = new Singleton();
				}
			}
		}
		return instance;
	}
}
